package com.cuanbobox.activity;

import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.opengl.GLES20;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.PointerIcon;
import android.view.SurfaceView;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.cuanbobox.adapter.ImgAdapter;
import com.cuanbobox.adapter.InOutAdapter;
import com.cuanbobox.adapter.PPTAdapter;
import com.cuanbobox.adapter.WdsAdapter;
import com.cuanbobox.base.App;
import com.cuanbobox.base.LHBaseActivity;
import com.cuanbobox.bean.DataK200Bean;
import com.cuanbobox.bean.DataList;
import com.cuanbobox.bean.EventBusBean;
import com.cuanbobox.bean.ImgBean;
import com.cuanbobox.bean.InOutBean;
import com.cuanbobox.bean.MatrixSlefCheckBean;
import com.cuanbobox.bean.PPTBean;
import com.cuanbobox.bean.WdsBean;
import com.cuanbobox.bean.WdsDataList;
import com.cuanbobox.cbavcx.R;
import com.cuanbobox.constant.CbConstant;
import com.cuanbobox.constant.MatrixConstant;
import com.cuanbobox.receiver.CbReceiver;
import com.cuanbobox.receiver.MatrixBroadcastReceiver;
import com.cuanbobox.service.BackgroundService;
import com.cuanbobox.utils.ADBUtil;
import com.cuanbobox.utils.AppUtil;
import com.cuanbobox.utils.BitmapUtil;
import com.cuanbobox.utils.BtnUtil;
import com.cuanbobox.utils.Camera2Helper;
import com.cuanbobox.utils.DateUtil;
import com.cuanbobox.utils.DensityUtil;
import com.cuanbobox.utils.FileUtil;
import com.cuanbobox.utils.InOutUtil;
import com.cuanbobox.utils.IpUtil;
import com.cuanbobox.utils.LogUtil;
import com.cuanbobox.utils.SharedPreferencesUtil;
import com.cuanbobox.utils.TimerThread;
import com.cuanbobox.utils.ToastUtil;
import com.cuanbobox.utils.TouchHelper;
import com.cuanbobox.utils.ViewUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainActivity extends LHBaseActivity implements TextureView.SurfaceTextureListener, MatrixBroadcastReceiver.MatrixListener, TimerThread.OnDoWorkListener, CbReceiver.CbListener {
    private ViewGroup rootView;
    private TouchHelper touchHelper;
    private Camera2Helper camera2Helper;
    private TextureView textureView;
    private ImageView ivWhiteBoard;
    private TextView tvWhiteBoard;
    private ImageView ivComment;
    private TextView tvComment;
    private ImageView ivHome;
    private TextView tvHome;
    private ImageView ivInteraction;
    private TextView tvInteraction;
    private ImageView ivCheckingIn;
    private TextView tvCheckingIn;
    private ImageView ivSignalSource;
    private TextView tvSignalSource;
    private ImageView ivCenterControl;
    private ImageView ivFile;
    private TextView tvFile;
    private ImageView ivMore;
    private TextView tvMore;
    private View flMenu;
    private boolean whiteBoard=false;
    public static boolean comment=false;
    private View ivShowMenu;
    private MatrixBroadcastReceiver matrixBroadcastReceiver;
    private View llCenterControl;
    private View llRecordControl;
    private LinearLayout llInOut;
    private RecyclerView rvOut;
    private RecyclerView rvIn;
    private List<InOutBean> inList = new ArrayList<>();
    private List<InOutBean> outList = new ArrayList<>();
    public static String[] pptNote=null;
    private int selInIndex = -1;
    private int selOutIndex = -1;
    private InOutAdapter inAdapter;
    private InOutBean selInBean;
    private InOutAdapter outAdapter;
    private InOutBean selOutBean;
    private InOutBean selEditBean;
    private RelativeLayout llEditInOut;
    private EditText etInOutName;
    private TextView tvEditInOutSave;
    private TextView tvEditInOutCancel;
    private LinearLayout llSignIn;
    private TimerThread timerThread;
    private TextView tvClass;
    private TextView tvTime;
    private View llHome;
    private ImageView ivScreenshot;
    private TextView tvScreenshot;
    private View drawBoard;
    private ImgAdapter imgAdapter;
    private RecyclerView rvImg;
    private LinearLayout llImg;
    private TextView tvDate;
    private long time;
    private int selectImg=0;
    private View llCompare;
    private ImageView ivImg1;
    private ImageView ivImg2;
    private View flCompare;
    private ImageView ivCompare;
    private TextView tvCompare;
    public static boolean isCompare;
    private View ivCode;
    private boolean bl1;
    private boolean bl2;
    private boolean bl3;
    private View rlBtn1;
    private View rlBtn2;
    private View rlBtn3;
    private View vTouch;
    private TextView tvCode;
    private ImageView ivCodeImg;
    private TextView tvShareMode;
    private View llShare;
    public static List<WdsBean> wdslst=new ArrayList<>();
    private CbReceiver cbReceiver;
    private RecyclerView rvWds;
    private RecyclerView rvPPT;
    private WdsAdapter wdsAdapter;
    public static int sumPage=0;
    public static List<PPTBean> pptLst=new ArrayList<>();
    private PPTAdapter pptAdapter;
    private TextView tvCenterControl;
    private ImageView ivRecord;
    private TextView tvRecord;
    private ImageView ivRemote;
    private TextView tvRemote;
    private LinearLayout llPPT;
    private ImageView ivBZ;
    private TextView tvBZ;
    private TextView tvBzContent;
    public static int nowPage=1;
    private TextView tvPPTPage;
    public TextView tvPCState;
    public static long signalRecord;
    private TextView tvSignal;
    private boolean bzCheck=false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        rootView= (ViewGroup) LayoutInflater.from(this).inflate(R.layout.activity_main,null);
        setContentView(rootView);
        init();
    }

    public void init(){
        if(wdslst.size()==0){
            wdslst.add(0,new WdsBean("返回桌面","返回桌面","",0));
        }
        EventBus.getDefault().register(this);
        initView();
        rlBtn1 = findViewById(R.id.rlBtn1);
        rlBtn2 = findViewById(R.id.rlBtn2);
        rlBtn3 = findViewById(R.id.rlBtn3);
        View rlBtn4=findViewById(R.id.rlBtn4);
        View rlBtn5=findViewById(R.id.rlBtn5);
        View rlBtn6=findViewById(R.id.rlBtn6);
        View rlBtn7=findViewById(R.id.rlBtn7);
        View rlBtn8=findViewById(R.id.rlBtn8);
        View rlBtn9=findViewById(R.id.rlBtn9);

        rlBtn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bl2=false;
                bl3=false;
                rlBtn1.setBackgroundResource(R.drawable.in_out_uncheck_bg);
                rlBtn2.setBackgroundResource(R.drawable.in_out_uncheck_bg);
                rlBtn3.setBackgroundResource(R.drawable.in_out_uncheck_bg);

                bl1=!bl1;
                if(bl1){
                    v.setBackgroundResource(R.drawable.in_out_check_bg);
                }else{
                    v.setBackgroundResource(R.drawable.in_out_uncheck_bg);
                }
            }
        });

        rlBtn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bl1=false;
                bl3=false;
                rlBtn1.setBackgroundResource(R.drawable.in_out_uncheck_bg);
                rlBtn2.setBackgroundResource(R.drawable.in_out_uncheck_bg);
                rlBtn3.setBackgroundResource(R.drawable.in_out_uncheck_bg);
                bl2=!bl2;
                if(bl2){
                    v.setBackgroundResource(R.drawable.in_out_check_bg);
                }else{
                    v.setBackgroundResource(R.drawable.in_out_uncheck_bg);
                }
            }
        });

        rlBtn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bl1=false;
                bl2=false;
                rlBtn1.setBackgroundResource(R.drawable.in_out_uncheck_bg);
                rlBtn2.setBackgroundResource(R.drawable.in_out_uncheck_bg);
                rlBtn3.setBackgroundResource(R.drawable.in_out_uncheck_bg);
                bl3=!bl3;
                if(bl3){
                    v.setBackgroundResource(R.drawable.in_out_check_bg);
                }else{
                    v.setBackgroundResource(R.drawable.in_out_uncheck_bg);
                }
            }
        });

        new BtnUtil(rlBtn4);
        new BtnUtil(rlBtn5);
        new BtnUtil(rlBtn6);
        new BtnUtil(rlBtn7);
        new BtnUtil(rlBtn8);
        new BtnUtil(rlBtn9);
        //移除鼠标指针
        //getWindow().getDecorView().setPointerIcon(PointerIcon.load(getResources(), R.drawable.pointer_icon));
        touchHelper=new TouchHelper(textureView);
        textureView.setSurfaceTextureListener(this);
        timerThread=new TimerThread(this,1000);
        tvClass.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                App.configInfo.setClassRoomState(!App.configInfo.isClassRoomState());
                SharedPreferencesUtil.saveBean(MainActivity.this,App.configInfo);
                changeClassState();
            }

        });
        changeClassState();
        initImgAdapter();
        initWdsAdapter();
        initPPTAdapter();
        ivShowMenu.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                btnShowMenu(v);
            }
        });
        ivShowMenu.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                vTouch.setVisibility(View.VISIBLE);

                return true;
            }
        });
        vTouch.setOnTouchListener(new View.OnTouchListener(){
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                ivShowMenu.setX(event.getX()-DensityUtil.dp2px(20));
                ivShowMenu.setY(event.getY()-DensityUtil.dp2px(20));
                return true;
            }
        });
        registerReceiver(cbReceiver = new CbReceiver(this), new IntentFilter(CbConstant.ACTION));
        registerReceiver(matrixBroadcastReceiver = new MatrixBroadcastReceiver(this), new IntentFilter(MatrixConstant.MATRIX_ACTION));
    }

    public void initView() {
        tvPCState = findViewById(R.id.tvPCState);
        tvPPTPage = findViewById(R.id.tvPPTPage);
        llShare = findViewById(R.id.llShare);
        tvShareMode = findViewById(R.id.tvShareMode);
        ivCode = findViewById(R.id.ivCode);
        ivCompare = findViewById(R.id.ivCompare);
        tvCompare = findViewById(R.id.tvCompare);
        flCompare = findViewById(R.id.flCompare);
        llCompare = findViewById(R.id.llCompare);
        ivImg1 = findViewById(R.id.ivImg1);
        ivImg2 = findViewById(R.id.ivImg2);
        llImg = findViewById(R.id.llImg);
        tvDate = findViewById(R.id.tvDate);
        rvImg = findViewById(R.id.rvImg);
        rvWds = findViewById(R.id.rvWds);
        rvPPT = findViewById(R.id.rvPPT);
        drawBoard = findViewById(R.id.drawBoard);
        ivScreenshot = findViewById(R.id.ivScreenshot);
        tvScreenshot = findViewById(R.id.tvScreenshot);
        llHome = findViewById(R.id.llHome);
        tvTime = findViewById(R.id.tvTime);
        tvClass = findViewById(R.id.tvClass);
        llSignIn = findViewById(R.id.llSignIn);
        llEditInOut = findViewById(R.id.llEditInOut);
        etInOutName = findViewById(R.id.etInOutName);
        tvEditInOutSave = findViewById(R.id.tvEditInOutSave);
        tvEditInOutCancel = findViewById(R.id.tvEditInOutCancel);
        llInOut = findViewById(R.id.llInOut);
        rvOut = findViewById(R.id.rvOut);
        rvIn = findViewById(R.id.rvIn);
        llCenterControl = findViewById(R.id.llCenterControl);
        llRecordControl = findViewById(R.id.llRecordControl);
        flMenu = rootView.findViewById(R.id.flMenu);
        textureView = rootView.findViewById(R.id.textureView);
        ivWhiteBoard = rootView.findViewById(R.id.ivWhiteBoard);
        tvWhiteBoard = rootView.findViewById(R.id.tvWhiteBoard);
        ivComment = rootView.findViewById(R.id.ivComment);
        tvComment = rootView.findViewById(R.id.tvComment);
        ivHome = rootView.findViewById(R.id.ivHome);
        tvHome = rootView.findViewById(R.id.tvHome);
        ivInteraction = rootView.findViewById(R.id.ivInteraction);
        tvInteraction = rootView.findViewById(R.id.tvInteraction);
        ivCheckingIn = rootView.findViewById(R.id.ivCheckingIn);
        tvCheckingIn = rootView.findViewById(R.id.tvCheckingIn);
        ivSignalSource = rootView.findViewById(R.id.ivSignalSource);
        tvSignalSource = rootView.findViewById(R.id.tvSignalSource);
        ivCenterControl = rootView.findViewById(R.id.ivCenterControl);
        tvCenterControl = rootView.findViewById(R.id.tvCenterControl);
        ivRecord = rootView.findViewById(R.id.ivRecord);
        tvRecord = rootView.findViewById(R.id.tvRecord);
        ivRemote = rootView.findViewById(R.id.ivRemote);
        tvRemote = rootView.findViewById(R.id.tvRemote);
        ivFile = rootView.findViewById(R.id.ivFile);
        tvFile = rootView.findViewById(R.id.tvFile);
        ivMore = rootView.findViewById(R.id.ivMore);
        tvMore = rootView.findViewById(R.id.tvMore);
        ivShowMenu = rootView.findViewById(R.id.ivShowMenu);
        vTouch = rootView.findViewById(R.id.vTouch);
        tvCode = rootView.findViewById(R.id.tvCode);
        ivCodeImg = rootView.findViewById(R.id.ivCodeImg);
        llPPT = rootView.findViewById(R.id.llPPT);

        ivBZ = rootView.findViewById(R.id.ivBZ);
        tvBZ = rootView.findViewById(R.id.tvBZ);
        tvBzContent = rootView.findViewById(R.id.tvBzContent);

        tvSignal = rootView.findViewById(R.id.tvSignal);
    }
    
    @Override
    public void requestData() {
        
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        touchHelper.close();
        camera2Helper.stop();
        EventBus.getDefault().unregister(this);
        unregisterReceiver(matrixBroadcastReceiver);
        unregisterReceiver(cbReceiver);
    }

    @Override
    public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surface, int width, int height) {
        LogUtil.add("宽",""+ DensityUtil.getScreenWidth(this),"安卓盒子分辨率");
        LogUtil.add("高",""+DensityUtil.getScreenHeigth(this),"安卓盒子分辨率");
        camera2Helper = new Camera2Helper(this,textureView,DensityUtil.getScreenWidth(this),DensityUtil.getScreenHeigth(this));
        camera2Helper.start();
    }

    @Override
    public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surface, int width, int height) {
    }

    @Override
    public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface) {
        return false;
    }

    @Override
    public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {
        signalRecord=new Date().getTime();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void eventBus(EventBusBean eventBusBean) {
        if(eventBusBean.getType()== EventBusBean.BUTTON_COMMENTS_OFF){
            ivComment.setImageResource(R.mipmap.nav_pen);
            comment=false;
            tvComment.setTextColor(0xffc9d0dc);
            ivWhiteBoard.setImageResource(R.mipmap.nav_whiteboard);
            tvWhiteBoard.setTextColor(0xffc9d0dc);
            whiteBoard=false;
        } else if (eventBusBean.getType() == EventBusBean.EDIT_MODE) {

        } else if (eventBusBean.getType() == EventBusBean.EDIT_MODE) {

        } else if (eventBusBean.getType() == EventBusBean.DRAWBOARD_TOUCH) {
            btnMenuClose(null);
        } else if (eventBusBean.getType() == EventBusBean.REFRUSH_IN_OUT_ADAPTER) {
            refrushInOutUI();
        } else if (eventBusBean.getType() == EventBusBean.COMPARE) {
            String imgPath= (String) eventBusBean.getData();
            if(selectImg==1){
                Glide.with(app).load(imgPath).into(ivImg1);
            }else if(selectImg==2){
                Glide.with(app).load(imgPath).into(ivImg2);
            }
            btnMenuClose(null);
        } else if (eventBusBean.getType() == EventBusBean.WDS_BEAN) {
            WdsBean wdsBean= (WdsBean) eventBusBean.getData();
            //Log.i("luohao","Title="+wdsBean.getTitle());
        }
    }

    /**
     *退出金鱼拖拽模式
     */
    public void btnExitDragMode(View v){
        vTouch.setVisibility(View.GONE);
    }

    /**
     *白板
     */
    public void btnWhiteBoard(View v) {
        if(isCompare){
            btnHome(null);
        }
        isCompare=false;
        ivComment.setImageResource(R.mipmap.nav_pen);
        comment=false;
        tvComment.setTextColor(0xffc9d0dc);
        whiteBoard=!whiteBoard;
        if(whiteBoard){
            tvWhiteBoard.setTextColor(0xff1ba3fe);
            ivWhiteBoard.setImageResource(R.mipmap.nav_whiteboard_screen);
            EventBus.getDefault().post(new EventBusBean(EventBusBean.MODE_WHITE_BOARD));
            EventBus.getDefault().post(new EventBusBean(EventBusBean.BUTTON_COMMENTS_NO));
        }else{
            tvWhiteBoard.setTextColor(0xffc9d0dc);
            ivWhiteBoard.setImageResource(R.mipmap.nav_whiteboard);
            EventBus.getDefault().post(new EventBusBean(EventBusBean.BUTTON_COMMENTS_OFF));
        }
        flMenu.setVisibility(View.GONE);
        ivShowMenu.setVisibility(View.VISIBLE);
    }

    /**
     *圈点
     */
    public void btnComment(View v) {
        ivWhiteBoard.setImageResource(R.mipmap.nav_whiteboard);
        tvWhiteBoard.setTextColor(0xffc9d0dc);
        whiteBoard=false;
        
        comment=!comment;
        if(comment) {
            tvComment.setTextColor(0xff1ba3fe);
            ivComment.setImageResource(R.mipmap.nav_pen_screen);
            camera2Helper.takePicture();
            EventBus.getDefault().post(new EventBusBean(EventBusBean.BUTTON_COMMENTS_NO));
        }else{
            tvComment.setTextColor(0xffc9d0dc);
            ivComment.setImageResource(R.mipmap.nav_pen);
            EventBus.getDefault().post(new EventBusBean(EventBusBean.BUTTON_COMMENTS_OFF));
        }
        flMenu.setVisibility(View.GONE);
        ivShowMenu.setVisibility(View.VISIBLE);
    }

    /**
     *首页
     */
    public void btnHome(View v) {
        isCompare=false;
        ivCode.setVisibility(View.GONE);
        llImg.setVisibility(View.GONE);
        ivScreenshot.setImageResource(R.drawable.screenshot);
        ivHome.setImageResource(R.mipmap.nav_home);
        ivInteraction.setImageResource(R.mipmap.nav_interaction);
        ivCheckingIn.setImageResource(R.mipmap.nav_kaoqin);
        ivSignalSource.setImageResource(R.mipmap.nav_signalsource_screen);
        ivCenterControl.setImageResource(R.mipmap.nav_centralcontrol);
        ivRecord.setImageResource(R.mipmap.nav_recordedbroadcast);
        ivRemote.setImageResource(R.mipmap.nav_remote);
        ivFile.setImageResource(R.mipmap.nav_file);
        ivMore.setImageResource(R.mipmap.nav_more);
        ivCompare.setImageResource(R.drawable.compare);
        tvCompare.setTextColor(0xffc9d0dc);
        tvHome.setTextColor(0xffc9d0dc);
        tvInteraction.setTextColor(0xffc9d0dc);
        tvCheckingIn.setTextColor(0xffc9d0dc);
        tvSignalSource.setTextColor(0xffc9d0dc);
        tvCenterControl.setTextColor(0xffc9d0dc);
        tvRecord.setTextColor(0xffc9d0dc);
        tvRemote.setTextColor(0xffc9d0dc);
        tvFile.setTextColor(0xffc9d0dc);
        tvMore.setTextColor(0xffc9d0dc);

        tvHome.setTextColor(0xff1ba3fe);
        ivHome.setImageResource(R.mipmap.nav_home_screen);

        llCompare.setVisibility(View.GONE);
        llImg.setVisibility(View.GONE);
        llHome.setVisibility(View.VISIBLE);
        llSignIn.setVisibility(View.GONE);
        llCenterControl.setVisibility(View.GONE);
        llRecordControl.setVisibility(View.GONE);
        llInOut.setVisibility(View.GONE);
    }

    /**
     *互动
     */
    public void btnInteraction(View v) {
        isCompare=false;
        ivCode.setVisibility(View.GONE);
        llImg.setVisibility(View.GONE);
        ivScreenshot.setImageResource(R.drawable.screenshot);
        ivHome.setImageResource(R.mipmap.nav_home);
        ivInteraction.setImageResource(R.mipmap.nav_interaction);
        ivCheckingIn.setImageResource(R.mipmap.nav_kaoqin);
        ivSignalSource.setImageResource(R.mipmap.nav_signalsource_screen);
        ivCenterControl.setImageResource(R.mipmap.nav_centralcontrol);
        ivRecord.setImageResource(R.mipmap.nav_recordedbroadcast);
        ivRemote.setImageResource(R.mipmap.nav_remote);
        ivFile.setImageResource(R.mipmap.nav_file);
        ivMore.setImageResource(R.mipmap.nav_more);
        ivCompare.setImageResource(R.drawable.compare);
        tvCompare.setTextColor(0xffc9d0dc);
        tvHome.setTextColor(0xffc9d0dc);
        tvInteraction.setTextColor(0xffc9d0dc);
        tvCheckingIn.setTextColor(0xffc9d0dc);
        tvSignalSource.setTextColor(0xffc9d0dc);
        tvCenterControl.setTextColor(0xffc9d0dc);
        tvRecord.setTextColor(0xffc9d0dc);
        tvRemote.setTextColor(0xffc9d0dc);
        tvFile.setTextColor(0xffc9d0dc);
        tvMore.setTextColor(0xffc9d0dc);

        tvInteraction.setTextColor(0xff1ba3fe);
        ivInteraction.setImageResource(R.mipmap.nav_interaction_screen);
    }

    /**
     *考勤
     */
    public void btnCheckingIn(View v) {
        tvCode.setText("请扫描下方二维码签到");
        if(ivCode.getVisibility()==View.VISIBLE){
            btnHome(null);
        }else if(ivCode.getVisibility()==View.GONE){
            isCompare=false;
            ivCode.setVisibility(View.GONE);
            llImg.setVisibility(View.GONE);
            ivScreenshot.setImageResource(R.drawable.screenshot);
            ivHome.setImageResource(R.mipmap.nav_home);
            ivInteraction.setImageResource(R.mipmap.nav_interaction);
            ivCheckingIn.setImageResource(R.mipmap.nav_kaoqin);
            ivSignalSource.setImageResource(R.mipmap.nav_signalsource_screen);
            ivCenterControl.setImageResource(R.mipmap.nav_centralcontrol);
            ivRecord.setImageResource(R.mipmap.nav_recordedbroadcast);
            ivRemote.setImageResource(R.mipmap.nav_remote);
            ivFile.setImageResource(R.mipmap.nav_file);
            ivMore.setImageResource(R.mipmap.nav_more);
            ivCompare.setImageResource(R.drawable.compare);
            tvCompare.setTextColor(0xffc9d0dc);
            tvHome.setTextColor(0xffc9d0dc);
            tvInteraction.setTextColor(0xffc9d0dc);
            tvCheckingIn.setTextColor(0xffc9d0dc);
            tvSignalSource.setTextColor(0xffc9d0dc);
            tvCenterControl.setTextColor(0xffc9d0dc);
            tvRecord.setTextColor(0xffc9d0dc);
            tvRemote.setTextColor(0xffc9d0dc);
            tvFile.setTextColor(0xffc9d0dc);
            tvMore.setTextColor(0xffc9d0dc);

            tvCheckingIn.setTextColor(0xff1ba3fe);
            ivCheckingIn.setImageResource(R.mipmap.nav_kaoqin_screen);

            llCompare.setVisibility(View.GONE);
            llImg.setVisibility(View.GONE);
            llSignIn.setVisibility(View.VISIBLE);
            llCenterControl.setVisibility(View.GONE);
            llRecordControl.setVisibility(View.GONE);
            llInOut.setVisibility(View.GONE);
            ivCode.setVisibility(View.VISIBLE);

        }
        btnMenuClose(null);
    }

    /**
     *信号源
     */
    public void btnSignalSource(View v) {
        isCompare=false;
        llImg.setVisibility(View.GONE);
        ivCode.setVisibility(View.GONE);
        ivScreenshot.setImageResource(R.drawable.screenshot);
        ivHome.setImageResource(R.mipmap.nav_home);
        ivInteraction.setImageResource(R.mipmap.nav_interaction);
        ivCheckingIn.setImageResource(R.mipmap.nav_kaoqin);
        ivSignalSource.setImageResource(R.mipmap.nav_signalsource_screen);
        ivCenterControl.setImageResource(R.mipmap.nav_centralcontrol);
        ivRecord.setImageResource(R.mipmap.nav_recordedbroadcast);
        ivRemote.setImageResource(R.mipmap.nav_remote);
        ivFile.setImageResource(R.mipmap.nav_file);
        ivMore.setImageResource(R.mipmap.nav_more);
        ivCompare.setImageResource(R.drawable.compare);
        tvCompare.setTextColor(0xffc9d0dc);
        tvHome.setTextColor(0xffc9d0dc);
        tvInteraction.setTextColor(0xffc9d0dc);
        tvCheckingIn.setTextColor(0xffc9d0dc);
        tvSignalSource.setTextColor(0xffc9d0dc);
        tvCenterControl.setTextColor(0xffc9d0dc);
        tvRecord.setTextColor(0xffc9d0dc);
        tvRemote.setTextColor(0xffc9d0dc);
        tvFile.setTextColor(0xffc9d0dc);
        tvMore.setTextColor(0xffc9d0dc);

        tvSignalSource.setTextColor(0xff1ba3fe);
        ivSignalSource.setImageResource(R.mipmap.nav_signalsource_screen1);

        llSignIn.setVisibility(View.GONE);
        llCenterControl.setVisibility(View.GONE);
        llRecordControl.setVisibility(View.GONE);
        llInOut.setVisibility(View.VISIBLE);
        llHome.setVisibility(View.GONE);
    }

    /**
     *中控
     */
    public void btnCenterControl(View v) {
        isCompare=false;
        llImg.setVisibility(View.GONE);
        ivCode.setVisibility(View.GONE);
        ivScreenshot.setImageResource(R.drawable.screenshot);
        ivHome.setImageResource(R.mipmap.nav_home);
        ivInteraction.setImageResource(R.mipmap.nav_interaction);
        ivCheckingIn.setImageResource(R.mipmap.nav_kaoqin);
        ivSignalSource.setImageResource(R.mipmap.nav_signalsource_screen);
        ivCenterControl.setImageResource(R.mipmap.nav_centralcontrol);
        ivRecord.setImageResource(R.mipmap.nav_recordedbroadcast);
        ivRemote.setImageResource(R.mipmap.nav_remote);
        ivFile.setImageResource(R.mipmap.nav_file);
        ivMore.setImageResource(R.mipmap.nav_more);
        ivCompare.setImageResource(R.drawable.compare);
        tvCompare.setTextColor(0xffc9d0dc);
        tvHome.setTextColor(0xffc9d0dc);
        tvInteraction.setTextColor(0xffc9d0dc);
        tvCheckingIn.setTextColor(0xffc9d0dc);
        tvSignalSource.setTextColor(0xffc9d0dc);
        tvCenterControl.setTextColor(0xffc9d0dc);
        tvRecord.setTextColor(0xffc9d0dc);
        tvRemote.setTextColor(0xffc9d0dc);
        tvFile.setTextColor(0xffc9d0dc);
        tvMore.setTextColor(0xffc9d0dc);


        tvCenterControl.setTextColor(0xff1ba3fe);
        ivCenterControl.setImageResource(R.mipmap.nav_centralcontrol_screen);

        llCompare.setVisibility(View.GONE);
        llImg.setVisibility(View.GONE);
        llSignIn.setVisibility(View.GONE);
        llCenterControl.setVisibility(View.VISIBLE);
        llRecordControl.setVisibility(View.GONE);
        llInOut.setVisibility(View.GONE);
        llHome.setVisibility(View.GONE);
    }

    /**
     *对比
     */
    public void btnCompare(View v) {
        if(isCompare){
            if(comment){
                btnComment(null);
            }
            btnHome(null);
        }else{
            if(whiteBoard){
                btnWhiteBoard(null);
            }
            if(comment){
                btnComment(null);
            }
            ivImg1.setImageResource(R.drawable.img1_bg);
            ivImg2.setImageResource(R.drawable.img2_bg);
            isCompare=false;
            ivWhiteBoard.setImageResource(R.mipmap.nav_whiteboard);
            tvWhiteBoard.setTextColor(0xffc9d0dc);
            whiteBoard=false;
            llImg.setVisibility(View.GONE);
            ivScreenshot.setImageResource(R.drawable.screenshot);
            ivHome.setImageResource(R.mipmap.nav_home);
            ivInteraction.setImageResource(R.mipmap.nav_interaction);
            ivCheckingIn.setImageResource(R.mipmap.nav_kaoqin);
            ivSignalSource.setImageResource(R.mipmap.nav_signalsource_screen);
            ivCenterControl.setImageResource(R.mipmap.nav_centralcontrol);
            ivRecord.setImageResource(R.mipmap.nav_recordedbroadcast);
            ivRemote.setImageResource(R.mipmap.nav_remote);
            ivFile.setImageResource(R.mipmap.nav_file);
            ivMore.setImageResource(R.mipmap.nav_more);
            ivCompare.setImageResource(R.drawable.compare);
            tvCompare.setTextColor(0xffc9d0dc);
            tvHome.setTextColor(0xffc9d0dc);
            tvInteraction.setTextColor(0xffc9d0dc);
            tvCheckingIn.setTextColor(0xffc9d0dc);
            tvSignalSource.setTextColor(0xffc9d0dc);
            tvCenterControl.setTextColor(0xffc9d0dc);
            tvRecord.setTextColor(0xffc9d0dc);
            tvRemote.setTextColor(0xffc9d0dc);
            tvFile.setTextColor(0xffc9d0dc);
            tvMore.setTextColor(0xffc9d0dc);


            ivCompare.setImageResource(R.drawable.compare_ck);
            tvCompare.setTextColor(0xff1ba3fe);

            ivCode.setVisibility(View.GONE);
            llImg.setVisibility(View.GONE);
            llSignIn.setVisibility(View.GONE);
            llCenterControl.setVisibility(View.GONE);
            llRecordControl.setVisibility(View.GONE);
            llInOut.setVisibility(View.GONE);
            llHome.setVisibility(View.GONE);
            llCompare.setVisibility(View.VISIBLE);
            isCompare=true;

            btnMenuClose(null);
        }
    }

    /**
     *录播
     */
    public void btnRecord(View v) {
        isCompare=false;
        llImg.setVisibility(View.GONE);
        ivCode.setVisibility(View.GONE);
        ivScreenshot.setImageResource(R.drawable.screenshot);
        ivHome.setImageResource(R.mipmap.nav_home);
        ivInteraction.setImageResource(R.mipmap.nav_interaction);
        ivCheckingIn.setImageResource(R.mipmap.nav_kaoqin);
        ivSignalSource.setImageResource(R.mipmap.nav_signalsource_screen);
        ivCenterControl.setImageResource(R.mipmap.nav_centralcontrol);
        ivRecord.setImageResource(R.mipmap.nav_recordedbroadcast);
        ivRemote.setImageResource(R.mipmap.nav_remote);
        ivFile.setImageResource(R.mipmap.nav_file);
        ivMore.setImageResource(R.mipmap.nav_more);
        ivCompare.setImageResource(R.drawable.compare);
        tvCompare.setTextColor(0xffc9d0dc);
        tvHome.setTextColor(0xffc9d0dc);
        tvInteraction.setTextColor(0xffc9d0dc);
        tvCheckingIn.setTextColor(0xffc9d0dc);
        tvSignalSource.setTextColor(0xffc9d0dc);
        tvCenterControl.setTextColor(0xffc9d0dc);
        tvRecord.setTextColor(0xffc9d0dc);
        tvRemote.setTextColor(0xffc9d0dc);
        tvFile.setTextColor(0xffc9d0dc);
        tvMore.setTextColor(0xffc9d0dc);

        tvRecord.setTextColor(0xff1ba3fe);
        ivRecord.setImageResource(R.mipmap.nav_recordedbroadcast_screen);

        llCompare.setVisibility(View.GONE);
        llImg.setVisibility(View.GONE);
        llSignIn.setVisibility(View.GONE);
        llCenterControl.setVisibility(View.GONE);
        llRecordControl.setVisibility(View.VISIBLE);
        llInOut.setVisibility(View.GONE);
        llHome.setVisibility(View.GONE);
    }

    /**
     *远程
     */
    public void btnRemote(View v) {
        isCompare=false;
        llImg.setVisibility(View.GONE);
        ivCode.setVisibility(View.GONE);
        ivScreenshot.setImageResource(R.drawable.screenshot);
        ivHome.setImageResource(R.mipmap.nav_home);
        ivInteraction.setImageResource(R.mipmap.nav_interaction);
        ivCheckingIn.setImageResource(R.mipmap.nav_kaoqin);
        ivSignalSource.setImageResource(R.mipmap.nav_signalsource_screen);
        ivCenterControl.setImageResource(R.mipmap.nav_centralcontrol);
        ivRecord.setImageResource(R.mipmap.nav_recordedbroadcast);
        ivRemote.setImageResource(R.mipmap.nav_remote);
        ivFile.setImageResource(R.mipmap.nav_file);
        ivMore.setImageResource(R.mipmap.nav_more);
        ivCompare.setImageResource(R.drawable.compare);
        tvCompare.setTextColor(0xffc9d0dc);
        tvHome.setTextColor(0xffc9d0dc);
        tvInteraction.setTextColor(0xffc9d0dc);
        tvCheckingIn.setTextColor(0xffc9d0dc);
        tvSignalSource.setTextColor(0xffc9d0dc);
        tvCenterControl.setTextColor(0xffc9d0dc);
        tvRecord.setTextColor(0xffc9d0dc);
        tvRemote.setTextColor(0xffc9d0dc);
        tvFile.setTextColor(0xffc9d0dc);
        tvMore.setTextColor(0xffc9d0dc);

        tvRemote.setTextColor(0xff1ba3fe);
        ivRemote.setImageResource(R.mipmap.nav_remote_screen);
    }

    /**
     *文件
     */
    public void btnFile(View v) {
        isCompare=false;
        ivScreenshot.setImageResource(R.drawable.screenshot);
        ivHome.setImageResource(R.mipmap.nav_home);
        ivInteraction.setImageResource(R.mipmap.nav_interaction);
        ivCheckingIn.setImageResource(R.mipmap.nav_kaoqin);
        ivSignalSource.setImageResource(R.mipmap.nav_signalsource_screen);
        ivCenterControl.setImageResource(R.mipmap.nav_centralcontrol);
        ivRecord.setImageResource(R.mipmap.nav_recordedbroadcast);
        ivRemote.setImageResource(R.mipmap.nav_remote);
        ivFile.setImageResource(R.mipmap.nav_file);
        ivMore.setImageResource(R.mipmap.nav_more);
        ivCompare.setImageResource(R.drawable.compare);
        tvCompare.setTextColor(0xffc9d0dc);
        tvHome.setTextColor(0xffc9d0dc);
        tvInteraction.setTextColor(0xffc9d0dc);
        tvCheckingIn.setTextColor(0xffc9d0dc);
        tvSignalSource.setTextColor(0xffc9d0dc);
        tvCenterControl.setTextColor(0xffc9d0dc);
        tvRecord.setTextColor(0xffc9d0dc);
        tvRemote.setTextColor(0xffc9d0dc);
        tvFile.setTextColor(0xffc9d0dc);
        tvMore.setTextColor(0xffc9d0dc);
        ivCode.setVisibility(View.GONE);
        llCenterControl.setVisibility(View.GONE);

        tvFile.setTextColor(0xff1ba3fe);
        ivFile.setImageResource(R.mipmap.nav_file_screen);
        time=new Date().getTime();
        tvDate.setText(DateUtil.fmtYMD());
        imgAdapter.setMode(0);
        imgAdapter.refurshData(DateUtil.fmtYMD());
        tvShareMode.setVisibility(View.VISIBLE);
        llShare.setVisibility(View.GONE);

        llImg.setVisibility(View.VISIBLE);
        llHome.setVisibility(View.GONE);
        llSignIn.setVisibility(View.GONE);
        llCenterControl.setVisibility(View.GONE);
        llRecordControl.setVisibility(View.GONE);
        llInOut.setVisibility(View.GONE);
        llCompare.setVisibility(View.GONE);

    }

    /**
     *更多
     */
    public void btnMore(View v) {
        isCompare=false;
        ivCode.setVisibility(View.GONE);
        llImg.setVisibility(View.GONE);
        ivScreenshot.setImageResource(R.drawable.screenshot);
        ivHome.setImageResource(R.mipmap.nav_home);
        ivInteraction.setImageResource(R.mipmap.nav_interaction);
        ivCheckingIn.setImageResource(R.mipmap.nav_kaoqin);
        ivSignalSource.setImageResource(R.mipmap.nav_signalsource_screen);
        ivCenterControl.setImageResource(R.mipmap.nav_centralcontrol);
        ivRecord.setImageResource(R.mipmap.nav_recordedbroadcast);
        ivRemote.setImageResource(R.mipmap.nav_remote);
        ivFile.setImageResource(R.mipmap.nav_file);
        ivMore.setImageResource(R.mipmap.nav_more);
        ivCompare.setImageResource(R.drawable.compare);
        tvCompare.setTextColor(0xffc9d0dc);
        tvHome.setTextColor(0xffc9d0dc);
        tvInteraction.setTextColor(0xffc9d0dc);
        tvCheckingIn.setTextColor(0xffc9d0dc);
        tvSignalSource.setTextColor(0xffc9d0dc);
        tvCenterControl.setTextColor(0xffc9d0dc);
        tvRecord.setTextColor(0xffc9d0dc);
        tvRemote.setTextColor(0xffc9d0dc);
        tvFile.setTextColor(0xffc9d0dc);
        tvMore.setTextColor(0xffc9d0dc);

        tvMore.setTextColor(0xff1ba3fe);
        ivMore.setImageResource(R.mipmap.nav_more_screen);

    }

    /**
     *截图
     */
    public void btnScreenshot(View v) {
        ToastUtil.show(app, "截图中,请稍后！");
        if(whiteBoard){
            App.capturePath=getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/capture/"+ DateUtil.fmtYMD()+"/";
            new File(App.capturePath).mkdirs();
            BitmapUtil.viewSaveToFile(App.capturePath+new Date().getTime()+".jpg",drawBoard);
        }else if(isCompare){
            App.capturePath=getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/capture/"+ DateUtil.fmtYMD()+"/";
            new File(App.capturePath).mkdirs();
            BitmapUtil.viewSaveToFile(App.capturePath+new Date().getTime()+".jpg",flCompare);
        }else if(comment){
            App.capturePath=getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/capture/"+ DateUtil.fmtYMD()+"/";
            new File(App.capturePath).mkdirs();
            BitmapUtil.viewSaveToFile(App.capturePath+new Date().getTime()+".jpg",drawBoard);
        }else{
            camera2Helper.takePicture();
        }
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                time=new Date().getTime();
                tvDate.setText(DateUtil.fmtYMD());
                imgAdapter.refurshData(DateUtil.fmtYMD());
            }
        },1000);
    }

    /**
     *关闭菜单栏
     */
    public void btnMenuClose(View v){
        flMenu.setVisibility(View.GONE);
        ivShowMenu.setVisibility(View.VISIBLE);
    }

    /**
     *打开菜单栏
     */
    public void btnShowMenu(View v) {
        flMenu.setVisibility(View.VISIBLE);
        ivShowMenu.setVisibility(View.GONE);
    }

    /**
    *退出考勤打卡界面
    */
    public void btnExitBar(View v){
        btnHome(null);
    }

    @Override
    public void initConnectSuccess() {

    }

    @Override
    public void initConnectFail() {

    }

    @Override
    public void initError() {

    }

    @Override
    public void receiveMsg(String msg) {

    }

    @Override
    public void receiveMsgFilter(String msg) {
        ViewUtil.changUI(rootView,msg);
    }

    @Override
    public void receiveError() {

    }

    @Override
    public void reConnect() {

    }

    @Override
    public void sendError() {

    }

    @Override
    public void classTimer() {

    }

    @Override
    public void reConnectTimer() {

    }

    @Override
    public void unConnectMatrixIp() {

    }

    @Override
    public void readMatrix16CInfoMsgSuccess(MatrixSlefCheckBean bean) {

    }

    @Override
    public void readMatrixK200CInfoMsgSuccess(DataK200Bean bean) {

    }

    /**
     *刷新输入输出界面
     */
    public void refrushInOutUI() {
        initInAdapter();
        initOutAdapter();
        if (llInOut.getVisibility() != View.VISIBLE) {
            App.readingMatrixInfo = false;
        }
    }

    /**
     *初始化输入列表
     */
    public void initInAdapter() {
        if (rvIn == null) return;
        if (App.configInfo.getInList() != null) {
            if (!InOutUtil.isEqual(inList, App.configInfo.getInList())) {
                inList.removeAll(inList);
                inList.addAll(App.configInfo.getInList());
            } else {
                InOutUtil.setData(inList, App.configInfo.getInList());
            }
        }
        if (selInIndex != -1 && selInIndex < inList.size()) {
            inList.get(selInIndex).setCheck(true);
        }
        SharedPreferencesUtil.saveBean(this, App.configInfo);
        if (inAdapter == null) {
            rvIn.setLayoutManager(new GridLayoutManager(this, 2));
            inAdapter = new InOutAdapter(inList);
            rvIn.setAdapter(inAdapter);
            inAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    selInIndex = position;
                    selInBean = (InOutBean) adapter.getData().get(position);
                    if (App.editMode) {
                        etInOutName.setText("" + selInBean.getName());
                        llEditInOut.setVisibility(View.VISIBLE);
                        selEditBean = selInBean;
                    }
                    for (int i = 0; i < adapter.getData().size(); i++) {
                        InOutBean bean = (InOutBean) adapter.getData().get(i);
                        if (i == position) {
                            bean.setCheck(true);
                        } else {
                            bean.setCheck(false);
                        }
                    }
                    inAdapter.notifyDataSetChanged();
                }
            });
        }
        inAdapter.notifyDataSetChanged();
    }

    /**
     *初始化输出列表
     */
    public void initOutAdapter() {
        if (rvOut == null) return;
        if (App.configInfo.getOutList() != null) {
            if (!InOutUtil.isEqual(outList, App.configInfo.getOutList())) {
                outList.removeAll(outList);
                outList.addAll(App.configInfo.getOutList());
            } else {
                InOutUtil.setData(outList, App.configInfo.getOutList());
            }
        }
        if (selOutIndex != -1 && selOutIndex < outList.size()) {
            outList.get(selOutIndex).setCheck(true);
        }
        SharedPreferencesUtil.saveBean(this, App.configInfo);
        if (outAdapter == null) {
            rvOut.setLayoutManager(new GridLayoutManager(this, 2));
            outAdapter = new InOutAdapter(outList);
            rvOut.setAdapter(outAdapter);
            outAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    if (selOutBean != null) {
                        selOutBean.setCheck(false);
                    }
                    selOutIndex = position;
                    selOutBean = (InOutBean) adapter.getData().get(position);
                    selOutBean.setCheck(true);
                    outAdapter.notifyDataSetChanged();
                    if (App.editMode) {
                        etInOutName.setText("" + selOutBean.getName());
                        llEditInOut.setVisibility(View.VISIBLE);
                        selEditBean = selOutBean;
                    } else {
                        if (selInBean != null) {
                            String cmd = ">C" + selInBean.getId() + "to" + selOutBean.getId() + ".";
                            DataList.add(cmd);
                            App.readingMatrixInfo = true;
                        }
                    }
                    InOutUtil.recordOutClickTime = new Date().getTime();
                }
            });
        }
        outAdapter.notifyDataSetChanged();
    }

    private void initImgAdapter() {
        rvImg.setLayoutManager(new GridLayoutManager(this, 2));
        imgAdapter = new ImgAdapter();
        rvImg.setAdapter(imgAdapter);
    }

    private void initWdsAdapter() {
        rvWds.setLayoutManager(new GridLayoutManager(this, 4));
        wdsAdapter = new WdsAdapter(wdslst);
        rvWds.setAdapter(wdsAdapter);
    }

    private void initPPTAdapter() {
        rvPPT.setLayoutManager(new GridLayoutManager(this, 2));
        pptAdapter = new PPTAdapter(pptLst);
        rvPPT.setAdapter(pptAdapter);
    }

    @Override
    public void doWork() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                tvTime.setText(""+DateUtil.getNowHMS());
            }
        });
    }

    private void changeClassState(){
        if(App.configInfo.isClassRoomState()){
            DataList.add("下课");
            tvClass.setText("上课");
            tvClass.setBackgroundResource(R.drawable.sk_bg);
        }else{
            DataList.add("上课");
            tvClass.setText("下课");
            tvClass.setBackgroundResource(R.drawable.xk_bg);
        }
    }

    public void btnMenuBg(View v){

    }

    /**
    * 上一页
    */
    public void upDate(View v){
        time=time-24*60*60*1000;
        String date=DateUtil.fmtYMD(time);
        tvDate.setText(date);
        imgAdapter.setMode(0);
        imgAdapter.refurshData(date);
        tvShareMode.setVisibility(View.VISIBLE);
        llShare.setVisibility(View.GONE);
    }

    /**
    * 下一页
    */
    public void nextDate(View v){
        time=time+24*60*60*1000;
        String date=DateUtil.fmtYMD(time);
        tvDate.setText(date);
        imgAdapter.setMode(0);
        imgAdapter.refurshData(date);
        tvShareMode.setVisibility(View.VISIBLE);
        llShare.setVisibility(View.GONE);
    }

    /**
     *分享模式
     */
    public void btnShareMode(View v){
        tvShareMode.setVisibility(View.GONE);
        llShare.setVisibility(View.VISIBLE);
        App.shareImgList=new ArrayList<>();
        String date=DateUtil.fmtYMD(time);
        tvDate.setText(date);
        imgAdapter.setMode(1);
        imgAdapter.refurshData(date);
    }

    /**
     *分享确认
     */
    public void btnShareConfirm(View v){
        tvCode.setText("请扫描下方二维码查看分享内容");
        String path= "http://"+IpUtil.getIpAddressString()+":8080/share";
        ivCodeImg.setImageBitmap(BitmapUtil.generateQRCodeBitmap(path));
        ivCode.setVisibility(View.VISIBLE);
        tvShareMode.setVisibility(View.VISIBLE);
        llShare.setVisibility(View.GONE);
        btnMenuClose(null);
    }

    /**
     *分享取消
     */
    public void btnShareCancel(View v){
        tvShareMode.setVisibility(View.VISIBLE);
        llShare.setVisibility(View.GONE);
        String date=DateUtil.fmtYMD(time);
        tvDate.setText(date);
        imgAdapter.setMode(0);
        imgAdapter.refurshData(date);
    }

    /**
    *对比图1
    */
    public void btnImg1(View v){
        selectImg=1;
        btnShowMenu(null);
        time=new Date().getTime();
        tvDate.setText(DateUtil.fmtYMD());
        imgAdapter.refurshData(DateUtil.fmtYMD());
        llImg.setVisibility(View.VISIBLE);
    }

    /**
     *对比图2
     */
    public void btnImg2(View v){
        selectImg=2;
        btnShowMenu(null);
        time=new Date().getTime();
        tvDate.setText(DateUtil.fmtYMD());
        imgAdapter.refurshData(DateUtil.fmtYMD());
        llImg.setVisibility(View.VISIBLE);
    }

    /**
    *退出对比
    */
    public void btnExitCompare(View v){
        if(comment){
            btnComment(null);
        }
        btnHome(null);
    }

    @Override
    public void installAPK(String path) {

    }

    //private long recordWdsUpdateTime=0;

    @Override
    public void wdsImg() {
/*        long diff=new Date().getTime()-recordWdsUpdateTime;
        if(diff<1000){
            return;
        }*/
        wdsAdapter.setNewData(new ArrayList<WdsBean>(wdslst));
        wdsAdapter.notifyDataSetChanged();
        //recordWdsUpdateTime=new Date().getTime();
    }

    private long recordPPTUpdateTime=0;

    @Override
    public void pptImg() {
/*        long diff=new Date().getTime()-recordPPTUpdateTime;
        if(diff<1000){
            return;
        }*/
        pptAdapter.notifyDataSetChanged();
        //recordPPTUpdateTime=new Date().getTime();
    }

    @Override
    public void pptEnd() {
        pptLst.removeAll(pptLst);
        pptAdapter.notifyDataSetChanged();
        llPPT.setVisibility(View.GONE);
    }

    @Override
    public void pptStart() {
        nowPage=1;
        bzCheck=false;
        ivBZ.setImageResource(R.drawable.pz);
        tvBZ.setTextColor(0xffffffff);
        tvBzContent.setVisibility(View.GONE);
        llPPT.setVisibility(View.VISIBLE);
        tvPPTPage.setText("PPT预览 ("+nowPage+"/"+sumPage+")");
    }

    @Override
    public void pptNote() {

    }

    @Override
    public void pptNowPate() {
        if(nowPage==-1){
            tvPPTPage.setText("PPT预览");
            return;
        }
        tvPPTPage.setText("PPT预览 ("+nowPage+"/"+sumPage+")");
    }

    @Override
    public void pcConnectedSuccess() {
        tvPCState.setText("");
    }

    @Override
    public void pcConnectedFail() {
        tvPCState.setText("(TCP连接失败)");
        wdslst.removeAll(wdslst);
        wdslst.add(0,new WdsBean("返回桌面","返回桌面","",0));
        wdsAdapter.setNewData(wdslst);
        wdsAdapter.notifyDataSetChanged();
        pptLst.removeAll(pptLst);
        pptAdapter.notifyDataSetChanged();
        llPPT.setVisibility(View.GONE);
        tvBzContent.setVisibility(View.GONE);
        tvPPTPage.setText("PPT预览");
        nowPage=1;
    }

    @Override
    public void pcIpEmpty() {
        tvPCState.setText("未配置电脑IP");
        wdslst.removeAll(wdslst);
        wdslst.add(0,new WdsBean("返回桌面","返回桌面","",0));
        wdsAdapter.setNewData(wdslst);
        wdsAdapter.notifyDataSetChanged();
        pptLst.removeAll(pptLst);
        pptAdapter.notifyDataSetChanged();
        llPPT.setVisibility(View.GONE);
        tvBzContent.setVisibility(View.GONE);
        tvPPTPage.setText("PPT预览");
        nowPage=1;
    }

    @Override
    public void noSignal() {
        if(tvSignal.getVisibility()!=View.VISIBLE) {
            tvSignal.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void haveSignal() {
        if(tvSignal.getVisibility()==View.VISIBLE) {
            tvSignal.setVisibility(View.GONE);
        }
    }

    /**
     *结束预览
     */
    public void btnPPTEnd(View v){
        WdsDataList.add(">PPT_End.");
        pptLst.removeAll(pptLst);
        pptAdapter.notifyDataSetChanged();
        llPPT.setVisibility(View.GONE);
        tvBzContent.setVisibility(View.GONE);
        tvPPTPage.setText("PPT预览");
        nowPage=1;
    }

    /**
     *ppt上一页
     */
    public void btnUpPPT(View v) {
        if(nowPage<=1)return;
        nowPage--;
        tvPPTPage.setText("PPT预览 ("+nowPage+"/"+sumPage+")");
        bzCheck=false;
        ivBZ.setImageResource(R.drawable.pz);
        tvBZ.setTextColor(0xffffffff);
        tvBzContent.setVisibility(View.GONE);
        WdsDataList.add(">PPT_Page:Last.");
    }

    /**
     *ppt下一页
     */
    public void btnNextPPT(View v) {
        if(nowPage>=sumPage)return;
        nowPage++;
        tvPPTPage.setText("PPT预览 ("+nowPage+"/"+sumPage+")");
        bzCheck=false;
        ivBZ.setImageResource(R.drawable.pz);
        tvBZ.setTextColor(0xffffffff);
        tvBzContent.setVisibility(View.GONE);
        WdsDataList.add(">PPT_Page:Next.");
    }

    /**
     *ppt备注
     */
    public void btnRemarks(View v) {
        bzCheck=!bzCheck;
        if(bzCheck){
            ivBZ.setImageResource(R.drawable.pz_ck);
            tvBZ.setTextColor(0xff1ba3fe);
            try{
                tvBzContent.setText(""+pptNote[nowPage+1]);
            }catch (Exception e){}
            tvBzContent.setVisibility(View.VISIBLE);
        }else{
            ivBZ.setImageResource(R.drawable.pz);
            tvBZ.setTextColor(0xffffffff);
            tvBzContent.setText("");
            tvBzContent.setVisibility(View.GONE);
        }

    }
}